/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.pc9.pswing.components;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.metal.MetalTextFieldUI;

/**
 *
 * @author paulocanedo
 */
public class InfoDialog {

    private GridBagConstraints gridBagConstraints;
//    private HudWindow hud = new HudWindow("Propriedades");
    private JDialog dialog;
    private int elements = -1;
    private Dimension dimension;

    public InfoDialog(JDialog parent) {
        dialog = new JDialog(parent);
        GridBagLayout gridBagLayout = new GridBagLayout();
        dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        dialog.getContentPane().setLayout(gridBagLayout);

        dimension = new Dimension(550, 300);
    }

    public void putLine(String label, Object content) {
        JLabel jlabel = new JLabel(label + ": ");
        jlabel.setHorizontalAlignment(JLabel.RIGHT);
        jlabel.setFont(jlabel.getFont().deriveFont(Font.BOLD));
        jlabel.setForeground(Color.LIGHT_GRAY);
        JTextField textField = new JTextField(content == null ? "" : content.toString());
        textField.setUI(new MetalTextFieldUI());
        textField.setEditable(false);
        textField.setBorder(new EmptyBorder(2, 2, 2, 2));
        textField.setFont(textField.getFont().deriveFont(Font.PLAIN));
        
        textField.setMinimumSize(new Dimension(400, 22));
        textField.setSize(new Dimension(400, 22));
        textField.setPreferredSize(new Dimension(400, 22));
        textField.putClientProperty("borderFocus", Boolean.FALSE);

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = ++elements;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        dialog.getContentPane().add(jlabel, gridBagConstraints);

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = elements;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        dialog.getContentPane().add(textField, gridBagConstraints);
    }

    public void setSize(int width, int height) {
        this.dimension = new Dimension(width, height);
    }

    public void setSize(Dimension dimension) {
        this.dimension = dimension;
    }
    
    public void display() {
        dialog.setSize(dimension);
        dialog.setLocationRelativeTo(null);

        dialog.setVisible(true);
    }
}
